dnl $Id$
dnl config.m4 for extension ctpp

PHP_ARG_ENABLE(ctpp, for ctpp support,
[ --enable-ctpp            Enable ctpp support])

  if test "$PHP_CTPP" != "no"; then

  # --with-ctpp -> check with-path
  if test -r $PHP_CTPP/include/ctpp2/CDT.hpp; then # path given as parameter
    CTPP_INCLUDE_DIR=$PHP_CTPP/include/ctpp2
    CTPP_LIB_DIR=$PHP_CTPP/lib
  else # search default path list
    SEARCH_INCLUDE_PATH="/usr/local/include/ctpp2 /usr/include/ctpp2 /opt/incude/ctpp2"
    AC_MSG_CHECKING([for ctpp header files in default path])
    for i in $SEARCH_INCLUDE_PATH ; do
       if test -r $i/CDT.hpp; then
         CTPP_INCLUDE_DIR=$i
         AC_MSG_RESULT(found in $i)
       fi
    done

    SEARCH_LIB_PATH="/usr/local/lib /usr/lib /opt/lib /usr/local/lib64 /usr/lib64 /opt/lib64"
    AC_MSG_CHECKING([for ctpp library in default path])
    for i in $SEARCH_LIB_PATH ; do
       if test -r $i/libctpp2.so; then
         CTPP_LIB_DIR=$i
         AC_MSG_RESULT(found in $i)
       fi
    done
  fi

  if test -z "$CTPP_INCLUDE_DIR"; then
    AC_MSG_RESULT([CTPP2 header files not found])
    AC_MSG_ERROR([Please reinstall the ctpp distribution])
  fi

  if test -z "$CTPP_LIB_DIR"; then
    AC_MSG_RESULT([CTPP2 librsry not found])
    AC_MSG_ERROR([Please reinstall the ctpp distribution])
  fi

  # --with-ctpp -> add include path
  PHP_ADD_INCLUDE($CTPP_INCLUDE_DIR)
  PHP_ADD_INCLUDE(/usr/include)
  PHP_ADD_INCLUDE(/usr/local/include)
  PHP_ADD_INCLUDE(/opt/include)

  # --with-ctpp -> check for lib and symbol presence
  LIBNAME=ctpp2
  PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $CTPP_LIB_DIR, CTPP_SHARED_LIBADD)

  PHP_SUBST(CTPP_SHARED_LIBADD)
  PHP_REQUIRE_CXX()
  PHP_ADD_LIBRARY(stdc++, 1, CTPP_SHARED_LIBADD)
  PHP_NEW_EXTENSION(ctpp, m_ctpp.cpp php_ctpp.cpp, $ext_shared)
fi

